﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TV.Translation.Library.Base
{
    public enum EventType
    {
        Primary,
        Snipe,
        Bug,
        Billing,
    }

    public abstract class DateTimeFrames : IComparable
    {
        protected DateTime m_dateTime;
        protected int m_frames;

        public DateTime DateTimeStamp
        {
            get { return m_dateTime; }
        }

        public int Frames
        {
            get { return m_frames; }
        }

        public abstract void setValue(String input);

        public override string ToString()
        {
            return m_dateTime.ToString("YYYYMMDD hh:mm:ss.") + m_frames.ToString("nnn");
        }

        public int CompareTo(Object obj)
        {
            DateTimeFrames compareObj = obj as DateTimeFrames;
            int dateTimeCompare = m_dateTime.CompareTo(compareObj.DateTimeStamp);
            if (dateTimeCompare == 0)
            {
                int framesCompare = m_frames.CompareTo(compareObj.Frames);
                if (framesCompare == 0) return 1;
                else return framesCompare;
            }
            return dateTimeCompare;
        }

    }

    public abstract class TimeSpanFrames : IComparable
    {
        protected TimeSpan m_timeSpan;
        protected int m_frames;

        public TimeSpan hhmmss
        {
            get { return m_timeSpan; }
            set { m_timeSpan = value; }
        }

        public int Frames
        {
            get { return m_frames; }
        }

        public abstract void setValue(String input);

        public int CompareTo(Object obj)
        {
            TimeSpanFrames compareObj = obj as TimeSpanFrames;
            int timespanCompare = m_timeSpan.CompareTo(compareObj.hhmmss);
            if (timespanCompare == 0)
            {
                return m_frames.CompareTo(compareObj.Frames);
            }
            return timespanCompare;
        }

    }

    public class BroadcastEvent
    {

        #region fields

        protected String id;
        protected DateTimeFrames startTime;
        protected TimeSpanFrames duration;
        protected String name;
        protected String mediaID;
        protected SortedList<DateTimeFrames, BroadcastEvent> m_secondary_events = null;
        protected EventType m_eventType;

        #endregion fields


        #region Properties

        public String ID
        {
            get { return id; }
            set { id = value; }
        }

        public DateTimeFrames Start
        {
            get { return startTime; }
        }

        public TimeSpanFrames Duration
        {
            get { return duration; }
        }

        public SortedList<DateTimeFrames, BroadcastEvent> SecondaryEvents
        {
            get { return m_secondary_events; }
        }

        public EventType Type
        {
            get { return m_eventType; }
        }


        #endregion Properties

        public void initializeSecondaryEvents()
        {
            m_secondary_events = new SortedList<DateTimeFrames, BroadcastEvent>();
        }

    }
}
